<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>声纹识别系统 - 管理界面</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
        }

        .header {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            padding: 20px 0;
            box-shadow: 0 2px 20px rgba(0, 0, 0, 0.1);
        }

        .header-content {
            max-width: 1200px;
            margin: 0 auto;
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 0 20px;
        }

        .logo {
            font-size: 1.8em;
            color: #667eea;
            font-weight: bold;
        }

        .user-info {
            display: flex;
            align-items: center;
            gap: 15px;
        }

        .logout-btn {
            background: #ff6b6b;
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 25px;
            cursor: pointer;
            font-size: 14px;
            transition: all 0.3s ease;
        }

        .logout-btn:hover {
            background: #ff5252;
            transform: translateY(-2px);
        }

        .main-container {
            max-width: 1200px;
            margin: 40px auto;
            padding: 0 20px;
        }

        .dashboard-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
            gap: 30px;
            margin-bottom: 40px;
        }

        .card {
            background: white;
            border-radius: 15px;
            padding: 30px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
            transition: transform 0.3s ease;
        }

        .card:hover {
            transform: translateY(-5px);
        }

        .card-header {
            display: flex;
            align-items: center;
            margin-bottom: 20px;
        }

        .card-icon {
            width: 50px;
            height: 50px;
            border-radius: 10px;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 24px;
            margin-right: 15px;
        }

        .user-icon {
            background: linear-gradient(45deg, #667eea, #764ba2);
            color: white;
        }

        .voice-icon {
            background: linear-gradient(45deg, #f093fb, #f5576c);
            color: white;
        }

        .system-icon {
            background: linear-gradient(45deg, #4facfe, #00f2fe);
            color: white;
        }

        .card-title {
            font-size: 1.3em;
            color: #333;
            font-weight: 600;
        }

        .card-content {
            color: #666;
            line-height: 1.6;
        }

        .stats-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 20px;
            margin-bottom: 30px;
        }

        .stat-card {
            background: white;
            border-radius: 10px;
            padding: 20px;
            text-align: center;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.08);
        }

        .stat-number {
            font-size: 2.5em;
            font-weight: bold;
            color: #667eea;
            margin-bottom: 5px;
        }

        .stat-label {
            color: #666;
            font-size: 14px;
        }

        .action-buttons {
            display: flex;
            gap: 15px;
            margin-top: 20px;
            flex-wrap: wrap;
        }

        .btn {
            padding: 12px 24px;
            border: none;
            border-radius: 25px;
            cursor: pointer;
            font-size: 14px;
            font-weight: 500;
            transition: all 0.3s ease;
            text-decoration: none;
            display: inline-block;
            text-align: center;
        }

        .btn-primary {
            background: linear-gradient(45deg, #667eea, #764ba2);
            color: white;
        }

        .btn-primary:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
        }

        .btn-secondary {
            background: linear-gradient(45deg, #f093fb, #f5576c);
            color: white;
        }

        .btn-secondary:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(240, 147, 251, 0.4);
        }

        .btn-info {
            background: linear-gradient(45deg, #4facfe, #00f2fe);
            color: white;
        }

        .btn-info:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(79, 172, 254, 0.4);
        }

        .recent-activity {
            background: white;
            border-radius: 15px;
            padding: 30px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
        }

        .activity-header {
            font-size: 1.3em;
            color: #333;
            margin-bottom: 20px;
            font-weight: 600;
        }

        .activity-item {
            display: flex;
            align-items: center;
            padding: 15px 0;
            border-bottom: 1px solid #f0f0f0;
        }

        .activity-item:last-child {
            border-bottom: none;
        }

        .activity-icon {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            background: linear-gradient(45deg, #667eea, #764ba2);
            color: white;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-right: 15px;
            font-size: 16px;
        }

        .activity-content {
            flex: 1;
        }

        .activity-title {
            font-weight: 500;
            color: #333;
            margin-bottom: 5px;
        }

        .activity-time {
            font-size: 12px;
            color: #999;
        }

        @media (max-width: 768px) {
            .header-content {
                flex-direction: column;
                gap: 15px;
            }

            .dashboard-grid {
                grid-template-columns: 1fr;
            }

            .stats-grid {
                grid-template-columns: repeat(2, 1fr);
            }

            .action-buttons {
                justify-content: center;
            }
        }
    </style>
</head>
<body>
    <div class="header">
        <div class="header-content">
            <div class="logo">🎤 声纹识别系统</div>
            <div class="user-info">
                <span id="welcomeText">欢迎，管理员</span>
                <button class="logout-btn" onclick="logout()">退出登录</button>
            </div>
        </div>
    </div>

    <div class="main-container">
        <!-- 统计数据 -->
        <div class="stats-grid">
            <div class="stat-card">
                <div class="stat-number" id="totalUsers">0</div>
                <div class="stat-label">注册用户</div>
            </div>
            <div class="stat-card">
                <div class="stat-number" id="voiceprintUsers">0</div>
                <div class="stat-label">声纹用户</div>
            </div>
            <div class="stat-card">
                <div class="stat-number" id="todayLogins">0</div>
                <div class="stat-label">今日登录</div>
            </div>
            <div class="stat-card">
                <div class="stat-number" id="systemStatus">正常</div>
                <div class="stat-label">系统状态</div>
            </div>
        </div>

        <!-- 功能模块 -->
        <div class="dashboard-grid">
            <div class="card">
                <div class="card-header">
                    <div class="card-icon user-icon">👥</div>
                    <div class="card-title">用户管理</div>
                </div>
                <div class="card-content">
                    管理系统用户，查看用户信息，启用或禁用用户账户，重置用户密码等操作。
                </div>
                <div class="action-buttons">
                    <button class="btn btn-primary" onclick="viewUsers()">查看用户</button>
                    <button class="btn btn-secondary" onclick="addUser()">添加用户</button>
                </div>
            </div>

            <div class="card">
                <div class="card-header">
                    <div class="card-icon voice-icon">🎵</div>
                    <div class="card-title">声纹管理</div>
                </div>
                <div class="card-content">
                    管理用户声纹特征，查看声纹注册情况，删除或重新注册声纹特征。
                </div>
                <div class="action-buttons">
                    <button class="btn btn-primary" onclick="viewVoiceprints()">声纹列表</button>
                    <button class="btn btn-info" onclick="voiceprintStats()">统计分析</button>
                </div>
            </div>

            <div class="card">
                <div class="card-header">
                    <div class="card-icon system-icon">⚙️</div>
                    <div class="card-title">系统设置</div>
                </div>
                <div class="card-content">
                    配置系统参数，调整声纹识别阈值，查看系统日志，备份数据等。
                </div>
                <div class="action-buttons">
                    <button class="btn btn-primary" onclick="systemSettings()">系统配置</button>
                    <button class="btn btn-info" onclick="viewLogs()">查看日志</button>
                </div>
            </div>
        </div>

        <!-- 最近活动 -->
        <div class="recent-activity">
            <div class="activity-header">最近活动</div>
            <div id="activityList">
                <div class="activity-item">
                    <div class="activity-icon">👤</div>
                    <div class="activity-content">
                        <div class="activity-title">用户 admin 登录成功</div>
                        <div class="activity-time">刚刚</div>
                    </div>
                </div>
                <div class="activity-item">
                    <div class="activity-icon">🎤</div>
                    <div class="activity-content">
                        <div class="activity-title">系统启动完成</div>
                        <div class="activity-time">5分钟前</div>
                    </div>
                </div>
                <div class="activity-item">
                    <div class="activity-icon">⚙️</div>
                    <div class="activity-content">
                        <div class="activity-title">声纹识别阈值已调整为 0.89</div>
                        <div class="activity-time">10分钟前</div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script>
        // 页面加载时初始化
        document.addEventListener('DOMContentLoaded', function() {
            loadDashboardData();
            
            // 从URL参数或localStorage获取用户信息
            const urlParams = new URLSearchParams(window.location.search);
            const username = urlParams.get('user') || localStorage.getItem('currentUser') || '管理员';
            document.getElementById('welcomeText').textContent = `欢迎，${username}`;
        });

        // 加载仪表板数据
        async function loadDashboardData() {
            try {
                // 这里可以调用实际的API获取统计数据
                // 暂时使用模拟数据
                document.getElementById('totalUsers').textContent = '12';
                document.getElementById('voiceprintUsers').textContent = '8';
                document.getElementById('todayLogins').textContent = '5';
                
                console.log('仪表板数据加载完成');
            } catch (error) {
                console.error('加载仪表板数据失败:', error);
            }
        }

        // 用户管理功能
        function viewUsers() {
            alert('用户列表功能开发中...');
            // 这里可以跳转到用户管理页面或显示用户列表模态框
        }

        function addUser() {
            alert('添加用户功能开发中...');
            // 这里可以显示添加用户的表单
        }

        // 声纹管理功能
        function viewVoiceprints() {
            alert('声纹列表功能开发中...');
            // 这里可以显示声纹特征列表
        }

        function voiceprintStats() {
            alert('声纹统计功能开发中...');
            // 这里可以显示声纹识别的统计图表
        }

        // 系统设置功能
        function systemSettings() {
            showConfigModal();
        }

        // 显示配置模态框
        function showConfigModal() {
            // 创建模态框HTML
            const modalHtml = `
                <div id="configModal" style="
                    position: fixed;
                    top: 0;
                    left: 0;
                    width: 100%;
                    height: 100%;
                    background: rgba(0,0,0,0.5);
                    display: flex;
                    justify-content: center;
                    align-items: center;
                    z-index: 1000;
                ">
                    <div style="
                        background: white;
                        border-radius: 15px;
                        padding: 30px;
                        width: 90%;
                        max-width: 500px;
                        box-shadow: 0 20px 40px rgba(0,0,0,0.3);
                    ">
                        <h3 style="margin-bottom: 20px; color: #333; text-align: center;">声纹识别阈值配置</h3>
                        
                        <div style="margin-bottom: 20px;">
                            <label style="display: block; margin-bottom: 8px; color: #666; font-weight: 500;">相似度阈值 (0.0 - 1.0):</label>
                            <input type="number" id="similarityThreshold" min="0" max="1" step="0.01" 
                                   style="width: 100%; padding: 12px; border: 2px solid #e0e0e0; border-radius: 8px; font-size: 16px;" 
                                   placeholder="当前值加载中...">
                            <small style="color: #999; font-size: 12px;">值越高要求越严格，建议范围: 0.7-0.9</small>
                        </div>
                        
                        <div style="margin-bottom: 30px;">
                            <label style="display: block; margin-bottom: 8px; color: #666; font-weight: 500;">声纹识别阈值 (0.0 - 1.0):</label>
                            <input type="number" id="voiceprintThreshold" min="0" max="1" step="0.01" 
                                   style="width: 100%; padding: 12px; border: 2px solid #e0e0e0; border-radius: 8px; font-size: 16px;" 
                                   placeholder="当前值加载中...">
                            <small style="color: #999; font-size: 12px;">值越高要求越严格，建议范围: 0.6-0.9</small>
                        </div>
                        
                        <div style="display: flex; gap: 15px; justify-content: center;">
                            <button onclick="saveConfig()" style="
                                background: linear-gradient(45deg, #667eea, #764ba2);
                                color: white;
                                border: none;
                                padding: 12px 24px;
                                border-radius: 25px;
                                cursor: pointer;
                                font-size: 14px;
                                font-weight: 500;
                            ">保存配置</button>
                            
                            <button onclick="resetConfig()" style="
                                background: linear-gradient(45deg, #f093fb, #f5576c);
                                color: white;
                                border: none;
                                padding: 12px 24px;
                                border-radius: 25px;
                                cursor: pointer;
                                font-size: 14px;
                                font-weight: 500;
                            ">重置默认</button>
                            
                            <button onclick="closeConfigModal()" style="
                                background: #ccc;
                                color: #666;
                                border: none;
                                padding: 12px 24px;
                                border-radius: 25px;
                                cursor: pointer;
                                font-size: 14px;
                                font-weight: 500;
                            ">取消</button>
                        </div>
                    </div>
                </div>
            `;
            
            // 添加模态框到页面
            document.body.insertAdjacentHTML('beforeend', modalHtml);
            
            // 加载当前配置
            loadCurrentConfig();
        }

        // 加载当前配置
        async function loadCurrentConfig() {
            try {
                const response = await fetch('/api/config/voiceprint');
                const result = await response.json();
                
                if (result.success) {
                    document.getElementById('similarityThreshold').value = result.data.similarityThreshold;
                    document.getElementById('voiceprintThreshold').value = result.data.voiceprintThreshold;
                } else {
                    showMessage('加载配置失败: ' + result.message, 'error');
                }
            } catch (error) {
                console.error('加载配置失败:', error);
                showMessage('加载配置失败', 'error');
            }
        }

        // 保存配置
        async function saveConfig() {
            try {
                const similarityThreshold = parseFloat(document.getElementById('similarityThreshold').value);
                const voiceprintThreshold = parseFloat(document.getElementById('voiceprintThreshold').value);
                
                // 验证输入
                if (isNaN(similarityThreshold) || similarityThreshold < 0 || similarityThreshold > 1) {
                    showMessage('相似度阈值必须在0.0-1.0之间', 'error');
                    return;
                }
                
                if (isNaN(voiceprintThreshold) || voiceprintThreshold < 0 || voiceprintThreshold > 1) {
                    showMessage('声纹识别阈值必须在0.0-1.0之间', 'error');
                    return;
                }
                
                const response = await fetch('/api/config/voiceprint/threshold', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    body: JSON.stringify({
                        similarityThreshold: similarityThreshold,
                        voiceprintThreshold: voiceprintThreshold
                    })
                });
                
                const result = await response.json();
                
                if (result.success) {
                    showMessage('配置保存成功', 'success');
                    closeConfigModal();
                    // 更新统计数据
                    loadDashboardData();
                } else {
                    showMessage('保存失败: ' + result.message, 'error');
                }
            } catch (error) {
                console.error('保存配置失败:', error);
                showMessage('保存配置失败', 'error');
            }
        }

        // 重置配置
        async function resetConfig() {
            if (!confirm('确定要重置为默认配置吗？')) {
                return;
            }
            
            try {
                const response = await fetch('/api/config/voiceprint/reset', {
                    method: 'POST'
                });
                
                const result = await response.json();
                
                if (result.success) {
                    showMessage('配置重置成功', 'success');
                    loadCurrentConfig(); // 重新加载配置
                } else {
                    showMessage('重置失败: ' + result.message, 'error');
                }
            } catch (error) {
                console.error('重置配置失败:', error);
                showMessage('重置配置失败', 'error');
            }
        }

        // 关闭配置模态框
        function closeConfigModal() {
            const modal = document.getElementById('configModal');
            if (modal) {
                modal.remove();
            }
        }

        function viewLogs() {
            alert('日志查看功能开发中...');
            // 这里可以显示系统日志
        }

        // 退出登录
        function logout() {
            if (confirm('确定要退出登录吗？')) {
                localStorage.removeItem('currentUser');
                localStorage.removeItem('loginTime');
                window.location.href = 'index.html';
            }
        }

        // 显示消息提示
        function showMessage(message, type = 'info') {
            // 创建消息元素
            const messageDiv = document.createElement('div');
            messageDiv.style.cssText = `
                position: fixed;
                top: 20px;
                right: 20px;
                padding: 15px 20px;
                border-radius: 5px;
                color: white;
                font-weight: 500;
                z-index: 1000;
                max-width: 300px;
                word-wrap: break-word;
                transition: all 0.3s ease;
            `;
            
            // 根据类型设置颜色
            switch(type) {
                case 'success':
                    messageDiv.style.background = 'linear-gradient(45deg, #4CAF50, #45a049)';
                    break;
                case 'error':
                    messageDiv.style.background = 'linear-gradient(45deg, #f44336, #da190b)';
                    break;
                case 'warning':
                    messageDiv.style.background = 'linear-gradient(45deg, #ff9800, #f57c00)';
                    break;
                default:
                    messageDiv.style.background = 'linear-gradient(45deg, #2196F3, #0b7dda)';
            }
            
            messageDiv.textContent = message;
            document.body.appendChild(messageDiv);
            
            // 3秒后自动移除
            setTimeout(() => {
                messageDiv.style.opacity = '0';
                messageDiv.style.transform = 'translateX(100%)';
                setTimeout(() => {
                    if (messageDiv.parentNode) {
                        messageDiv.parentNode.removeChild(messageDiv);
                    }
                }, 300);
            }, 3000);
        }
    </script>
</body>
</html>